import numpy as np


def calcEntropy(paiList):
    E = 0
    for pai in paiList:
        E += pai * np.log2(pai)
    E = E * (-1)
    return E


if __name__ == "__main__":
    E = 1
    ep = 0.00005
    paiMat = np.linspace(0, 1, 1000)
    paiMat = paiMat[1:-1]

    for x1 in paiMat:
        for x2 in paiMat:
            pl = [x1, x2]

            if abs(sum(pl)-1.0) < ep:
                c = calcEntropy(pl)
                if abs(c-E) < ep:
                    print(pl)
                    print(sum(pl))
                    print(c)
                    print('----')

# [0.4964964964964965, 0.5035035035035035]
# 1.0
# 0.9999645828834391
#

# [0.001001001001001001, 0.4394394394394394, 0.5595595595595596]
# 1.0
# 0.9999728395788392

#
# [0.001001001001001001, 0.001001001001001001, 0.4144144144144144, 0.5835835835835835]
# 1.0
# 1.0000467145585743

# [0.001001001001001001, 0.001001001001001001, 0.005005005005005005, 0.35235235235235235, 0.6406406406406406]
# 1.0
# 1.0000129889508995

# [0.001001001001001001, 0.001001001001001001, 0.001001001001001001, 0.005005005005005005, 0.34034034034034033, 0.6516516516516516]
# 1.0
# 0.9999935213939359

# [0.001001001001001001, 0.001001001001001001, 0.001001001001001001, 0.001001001001001001, 0.001001001001001001, 0.36436436436436437, 0.6306306306306306]
# 1.0
# 1.0000382645728878

# [0.001001001001001001, 0.001001001001001001, 0.001001001001001001, 0.001001001001001001, 0.001001001001001001, 0.001001001001001001, 0.35135135135135137, 0.6426426426426426]
# 1.0
# 0.9999889307960026

# [0.001001001001001001, 0.001001001001001001, 0.001001001001001001, 0.001001001001001001, 0.001001001001001001, 0.001001001001001001, 0.012012012012012012, 0.2732732732732733, 0.7087087087087087]
# 1.0
# 0.9999695175035936

# [0.001001001001001001, 0.001001001001001001, 0.001001001001001001, 0.001001001001001001, 0.001001001001001001, 0.001001001001001001, 0.001001001001001001, 0.03303303303303303, 0.2012012012012012, 0.7587587587587588]
# 1.0
# 0.9999811512764212